options compress=YES;
libname manasi ''; 
libname f831 ''; 

* CREATE VARIABLES FOR PARENT DI AND SSI APPLICATION;

%macro dissi(year);
	* Create variables for each observation;
	data f831.par831summ_&year.;
		set f831.f831_cy&year._parents;

		* Applied for DI (own) in year X;
		if BIC='A' & RID='2' then n_par831_diself_&year.=1;
			else n_par831_diself_&year.=0;

		* Applied for DI (other) in year X;
		if BIC^='A' & RID='2' then n_par831_dioth_&year.=1;
			else n_par831_dioth_&year.=0;

		* Applied for SSI (own) in year X;
		if BIC='A' & RID='R' then n_par831_ssiself_&year.=1;
			else n_par831_ssiself_&year.=0;

		* Applied for SSI (other) in year X;
		if BIC^='A' & RID='R' then n_par831_ssioth_&year.=1;
			else n_par831_ssioth_&year.=0;

		* Is diagnosis on app mental or musculoskeletal? ;
		if (rpdx>=2900 & rpdx<3200) | (rpdx>=7100 & rpdx<7400)
			then n_par831_diagmm_&year.=1;
			else n_par831_diagmm_&year.=0;

	run;

	* Collapse on SSN so that there is only one observation per person;
	proc means noprint data=f831.par831summ_&year.;
		by ssn;
		var n_par831_:;
		output out=f831.par831summ_&year.
			sum(n_par831_diself_&year. n_par831_dioth_&year. 
				n_par831_ssiself_&year. n_par831_ssioth_&year.) = 
				n_par831_diself_&year. n_par831_dioth_&year. 
				n_par831_ssiself_&year. n_par831_ssioth_&year.
			max(n_par831_diagmm_&year.) = n_par831_diagmm_&year.;
	run;
%mend dissi;

%dissi(1985);
%dissi(1986);
%dissi(1987);
%dissi(1988);
%dissi(1989);
%dissi(1990);
%dissi(1991);
%dissi(1992);
%dissi(1993);
%dissi(1994);
%dissi(1995);
%dissi(1996);
%dissi(1997);
%dissi(1998);
%dissi(1999);
%dissi(2000);
%dissi(2001);
%dissi(2002);
%dissi(2003);
%dissi(2004);
%dissi(2005);
%dissi(2006);
%dissi(2007);
%dissi(2008);
%dissi(2009);
%dissi(2010);
%dissi(2011);
